<!DOCTYPE html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Java学习,">










<meta name="description" content="摘要：变量在内存中进行储存时，首先需要申请空间，内存管理器是根据变量类型来进行分配空间的。分配的空间只能用来存储该类型的数据。因此通过定义不同的数据类型，可以在内存中存放小数，整数，字符。">
<meta name="keywords" content="Java学习">
<meta property="og:type" content="article">
<meta property="og:title" content="Java基础-Java数据的基本类型">
<meta property="og:url" content="/youbaaa.github.io/2017/08/04/Java基础-Java数据的基本类型/index.html">
<meta property="og:site_name" content="vlsion&#39;手记">
<meta property="og:description" content="摘要：变量在内存中进行储存时，首先需要申请空间，内存管理器是根据变量类型来进行分配空间的。分配的空间只能用来存储该类型的数据。因此通过定义不同的数据类型，可以在内存中存放小数，整数，字符。">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2019-08-07T00:19:04.451Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Java基础-Java数据的基本类型">
<meta name="twitter:description" content="摘要：变量在内存中进行储存时，首先需要申请空间，内存管理器是根据变量类型来进行分配空间的。分配的空间只能用来存储该类型的数据。因此通过定义不同的数据类型，可以在内存中存放小数，整数，字符。">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="/youbaaa.github.io/2017/08/04/Java基础-Java数据的基本类型/">





  <title>Java基础-Java数据的基本类型 | vlsion'手记</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">vlsion'手记</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">擅长Ai、Fw、Fl、Br、Ae、Pr、Id、PS等软件的安装与卸载，精通CSS、JavaScript、PHP、C、C＋＋、java、Ruby、Perl、Lisp、python、Objective-C、ActionScript等单词的拼写，熟悉windows、Linux、Mac、Android、IOS等系统的开关机</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="/youbaaa.github.io/2017/08/04/Java基础-Java数据的基本类型/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="vlsion_">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/uploads/girl.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="vlsion'手记">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Java基础-Java数据的基本类型</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-08-04T16:47:01+08:00">
                2017-08-04
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Java基础/" itemprop="url" rel="index">
                    <span itemprop="name">Java基础</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2017/08/04/Java基础-Java数据的基本类型/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count valine-comment-count" data-xid="/2017/08/04/Java基础-Java数据的基本类型/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          
             <span id="/2017/08/04/Java基础-Java数据的基本类型/" class="leancloud_visitors" data-flag-title="Java基础-Java数据的基本类型">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>摘要：变量在内存中进行储存时，首先需要申请空间，内存管理器是根据变量类型来进行分配空间的。分配的空间只能用来存储该类型的数据。<br>因此通过定义不同的数据类型，可以在内存中存放小数，整数，字符。</p>
<a id="more"></a>

<h3 id="了解"><a href="#了解" class="headerlink" title="了解"></a>了解</h3><p>了解数据的基本类型前，我们先来了解一下位、字节、字符、字符集、编码的意思；以及字节、位、bit、byte、KB、B、字符之间的关系；</p>
<ul>
<li><p>位（bit）：是数据存储中的最小单位，每个二进制中的0或者1就是一个位。</p>
</li>
<li><p>字节（byte）：8个位组成一个字节。</p>
</li>
<li><p>字符：a、A、中、+………都表示一个字符。</p>
</li>
<li><p>字符集：各个字符的集合。按照不同的标准收纳的字符集合。</p>
</li>
<li><p>编码：规定每个“字符”分别用一个字节还是多个字节存储，用哪些字节来存储，这个规定就叫做“编码“。</p>
<p>  1字节 = 8位 即为 1byte = 1bit 也是 1B = 8b</p>
<p>  1字符 = 2字节 = 16位</p>
<p>  1KB = 1024B</p>
</li>
</ul>
<p>Java中有俩大数据类型：分为:</p>
<ul>
<li><p>基本数据类型</p>
</li>
<li><p>引用数据类型</p>
</li>
</ul>
<h3 id="基本数据类型"><a href="#基本数据类型" class="headerlink" title="基本数据类型"></a>基本数据类型</h3><ul>
<li><p>byte<br>  占8位，带符号的整数。</p>
<p>  最小值：-2^7 = -128</p>
<p>  最大值：2^7-1 = 127</p>
<p>  默认值：0</p>
</li>
<li><p>short<br>  占16位，带符号的整数。</p>
<p>  最小值：-2^16 </p>
<p>  最大值：2^16-1</p>
<p>  默认值：0</p>
</li>
<li><p>int<br>  占32位，带符号的整数。</p>
<p>  最小值：-2^32</p>
<p>  最大值：2^32-1</p>
<p>  默认值：0</p>
</li>
<li><p>long<br>  占16位，带符号的整数。</p>
<p>  最小值：-2^64</p>
<p>  最大值：2^64-1</p>
<p>  默认值：0</p>
</li>
<li><p>float<br>  占32位，单精度浮点数。不能用来表示货币。</p>
<p>  默认值：0.0f</p>
</li>
<li><p>double<br>  占64位，双精度浮点数，是浮点数的默认类型，也不能用来表示精确的值，如货币。</p>
<p>  默认值：0.0d</p>
</li>
<li><p>boolean<br>  占1位，只有两个值true/false</p>
<p>  默认值：false</p>
</li>
<li><p>char<br>  char是一个单一的16位的Unicode字符；</p>
<p>  最小值：\u0000</p>
<p>  最大值：\uffff</p>
</li>
</ul>
<pre><code><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br></pre></td><td class="code"><pre><span class="line">测试：</span><br><span class="line"></span><br><span class="line">public class VlsionTest &#123;</span><br><span class="line">    public static void main(String[] args) &#123;</span><br><span class="line">        // byte</span><br><span class="line">        System.out.println(&quot;基本类型：byte 二进制位数：&quot; + Byte.SIZE);</span><br><span class="line">        System.out.println(&quot;包装类：java.lang.Byte&quot;);</span><br><span class="line">        System.out.println(&quot;最小值：Byte.MIN_VALUE=&quot; + Byte.MIN_VALUE);</span><br><span class="line">        System.out.println(&quot;最大值：Byte.MAX_VALUE=&quot; + Byte.MAX_VALUE);</span><br><span class="line">        System.out.println();</span><br><span class="line"></span><br><span class="line">        // short</span><br><span class="line">        System.out.println(&quot;基本类型：short 二进制位数：&quot; + Short.SIZE);</span><br><span class="line">        System.out.println(&quot;包装类：java.lang.Short&quot;);</span><br><span class="line">        System.out.println(&quot;最小值：Short.MIN_VALUE=&quot; + Short.MIN_VALUE);</span><br><span class="line">        System.out.println(&quot;最大值：Short.MAX_VALUE=&quot; + Short.MAX_VALUE);</span><br><span class="line">        System.out.println();</span><br><span class="line">    </span><br><span class="line">        // int</span><br><span class="line">        System.out.println(&quot;基本类型：int 二进制位数：&quot; + Integer.SIZE);</span><br><span class="line">        System.out.println(&quot;包装类：java.lang.Integer&quot;);</span><br><span class="line">        System.out.println(&quot;最小值：Integer.MIN_VALUE=&quot; + Integer.MIN_VALUE);</span><br><span class="line">        System.out.println(&quot;最大值：Integer.MAX_VALUE=&quot; + Integer.MAX_VALUE);</span><br><span class="line">        System.out.println();</span><br><span class="line">    </span><br><span class="line">        // long</span><br><span class="line">        System.out.println(&quot;基本类型：long 二进制位数：&quot; + Long.SIZE);</span><br><span class="line">        System.out.println(&quot;包装类：java.lang.Long&quot;);</span><br><span class="line">        System.out.println(&quot;最小值：Long.MIN_VALUE=&quot; + Long.MIN_VALUE);</span><br><span class="line">        System.out.println(&quot;最大值：Long.MAX_VALUE=&quot; + Long.MAX_VALUE);</span><br><span class="line">        System.out.println();</span><br><span class="line">    </span><br><span class="line">        // float</span><br><span class="line">        System.out.println(&quot;基本类型：float 二进制位数：&quot; + Float.SIZE);</span><br><span class="line">        System.out.println(&quot;包装类：java.lang.Float&quot;);</span><br><span class="line">        System.out.println(&quot;最小值：Float.MIN_VALUE=&quot; + Float.MIN_VALUE);</span><br><span class="line">        System.out.println(&quot;最大值：Float.MAX_VALUE=&quot; + Float.MAX_VALUE);</span><br><span class="line">        System.out.println();</span><br><span class="line">    </span><br><span class="line">        // double</span><br><span class="line">        System.out.println(&quot;基本类型：double 二进制位数：&quot; + Double.SIZE);</span><br><span class="line">        System.out.println(&quot;包装类：java.lang.Double&quot;);</span><br><span class="line">        System.out.println(&quot;最小值：Double.MIN_VALUE=&quot; + Double.MIN_VALUE);</span><br><span class="line">        System.out.println(&quot;最大值：Double.MAX_VALUE=&quot; + Double.MAX_VALUE);</span><br><span class="line">        System.out.println();</span><br><span class="line">    </span><br><span class="line">        // char</span><br><span class="line">        System.out.println(&quot;基本类型：char 二进制位数：&quot; + Character.SIZE);</span><br><span class="line">        System.out.println(&quot;包装类：java.lang.Character&quot;);</span><br><span class="line">        // 以数值形式而不是字符形式将Character.MIN_VALUE输出到控制台</span><br><span class="line">        System.out.println(&quot;最小值：Character.MIN_VALUE=&quot; + (int) Character.MIN_VALUE);</span><br><span class="line">        // 以数值形式而不是字符形式将Character.MAX_VALUE输出到控制台</span><br><span class="line">        System.out.println(&quot;最大值：Character.MAX_VALUE=&quot; + (int) Character.MAX_VALUE);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">结果：</span><br><span class="line">    基本类型：byte 二进制位数：8</span><br><span class="line">    包装类：java.lang.Byte</span><br><span class="line">    最小值：Byte.MIN_VALUE=-128</span><br><span class="line">    最大值：Byte.MAX_VALUE=127</span><br><span class="line"></span><br><span class="line">    基本类型：short 二进制位数：16</span><br><span class="line">    包装类：java.lang.Short</span><br><span class="line">    最小值：Short.MIN_VALUE=-32768</span><br><span class="line">    最大值：Short.MAX_VALUE=32767</span><br><span class="line"></span><br><span class="line">    基本类型：int 二进制位数：32</span><br><span class="line">    包装类：java.lang.Integer</span><br><span class="line">    最小值：Integer.MIN_VALUE=-2147483648</span><br><span class="line">    最大值：Integer.MAX_VALUE=2147483647</span><br><span class="line"></span><br><span class="line">    基本类型：long 二进制位数：64</span><br><span class="line">    包装类：java.lang.Long</span><br><span class="line">    最小值：Long.MIN_VALUE=-9223372036854775808</span><br><span class="line">    最大值：Long.MAX_VALUE=9223372036854775807</span><br><span class="line"></span><br><span class="line">    基本类型：float 二进制位数：32</span><br><span class="line">    包装类：java.lang.Float</span><br><span class="line">    最小值：Float.MIN_VALUE=1.4E-45</span><br><span class="line">    最大值：Float.MAX_VALUE=3.4028235E38</span><br><span class="line"></span><br><span class="line">    基本类型：double 二进制位数：64</span><br><span class="line">    包装类：java.lang.Double</span><br><span class="line">    最小值：Double.MIN_VALUE=4.9E-324</span><br><span class="line">    最大值：Double.MAX_VALUE=1.7976931348623157E308</span><br><span class="line"></span><br><span class="line">    基本类型：char 二进制位数：16</span><br><span class="line">    包装类：java.lang.Character</span><br><span class="line">    最小值：Character.MIN_VALUE=0</span><br><span class="line">    最大值：Character.MAX_VALUE=65535</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">默认值测试：</span><br><span class="line"></span><br><span class="line">public class VlsionTest &#123;</span><br><span class="line">    static boolean aBoolean;</span><br><span class="line">    static byte aByte;</span><br><span class="line">    static short aShort;</span><br><span class="line">    static int anInt;</span><br><span class="line">    static long aLong;</span><br><span class="line">    static float aFloat;</span><br><span class="line">    static double aDouble;</span><br><span class="line">    static char aChar;</span><br><span class="line">    static String  string;</span><br><span class="line">    public static void main(String[] args) &#123;</span><br><span class="line">        System.out.println(&quot;Bool :&quot; + aBoolean);</span><br><span class="line">        System.out.println(&quot;Byte :&quot; + aByte);</span><br><span class="line">        System.out.println(&quot;Character:&quot; + aChar);</span><br><span class="line">        System.out.println(&quot;Double :&quot; + aDouble);</span><br><span class="line">        System.out.println(&quot;Float :&quot; + aFloat);</span><br><span class="line">        System.out.println(&quot;Integer :&quot; + anInt);</span><br><span class="line">        System.out.println(&quot;Long :&quot; + aLong);</span><br><span class="line">        System.out.println(&quot;Short :&quot; + aShort);</span><br><span class="line">        System.out.println(&quot;String :&quot; + string);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">测试结果：</span><br><span class="line">    Bool :false</span><br><span class="line">    Byte :0</span><br><span class="line">    Character: </span><br><span class="line">    Double :0.0</span><br><span class="line">    Float :0.0</span><br><span class="line">    Integer :0</span><br><span class="line">    Long :0</span><br><span class="line">    Short :0</span><br><span class="line">    String :null</span><br></pre></td></tr></table></figure></code></pre><h3 id="引用数据类型"><a href="#引用数据类型" class="headerlink" title="引用数据类型"></a>引用数据类型</h3><p>引用数据类型从字面意思上来看，其实就是引用类型指向一个对象，指向对象的变量是引用变量。这些变量在声明的时候被指定为一个类型。变量一旦声明后，类型就不能被改变。<br>如下：都是引用数据类型。且所有引用类型的默认值都是null。</p>
<ul>
<li>类</li>
<li>接口</li>
<li>数组</li>
</ul>
<h3 id="Java常量"><a href="#Java常量" class="headerlink" title="Java常量"></a>Java常量</h3><p>Java常量一般用final 关键字来修饰，在程序运行时是不能被改变的。<br>声明如：final double PI = 3.1415926;<br>常量名一般为大写。是为了更好的区分。</p>
<h3 id="自动类型转换"><a href="#自动类型转换" class="headerlink" title="自动类型转换"></a>自动类型转换</h3><p>转换级别由低到高如下所示：</p>
<p>byte,short,char-&gt;int-&gt;long-&gt;float-&gt;double</p>
<p>1，Boolean是不能进行类型转换的</p>
<p>2，不能把对象转换成不相关的对象</p>
<p>3，容量大的转换成容量小的类型必须采用强制类型转换，但是转换过程可能导致溢出或者损失精度。<br>如：</p>
 <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">int i = 128</span><br><span class="line">byte m = (byte)i =-128</span><br><span class="line"></span><br><span class="line">int i = 127 </span><br><span class="line">byte m =(byte)i = 127</span><br></pre></td></tr></table></figure>

<p>tips：<br> 1，整数的默认类型是int</p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Java学习/" rel="tag"># Java学习</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/07/18/Java学习方向/" rel="next" title="Java学习方向">
                <i class="fa fa-chevron-left"></i> Java学习方向
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/08/08/Java对象初始化顺序探索/" rel="prev" title="Java对象初始化顺序探索">
                Java对象初始化顺序探索 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
    </div>
  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/uploads/girl.jpg" alt="vlsion_">
            
              <p class="site-author-name" itemprop="name">vlsion_</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">25</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">10</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">16</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#了解"><span class="nav-number">1.</span> <span class="nav-text">了解</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#基本数据类型"><span class="nav-number">2.</span> <span class="nav-text">基本数据类型</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#引用数据类型"><span class="nav-number">3.</span> <span class="nav-text">引用数据类型</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Java常量"><span class="nav-number">4.</span> <span class="nav-text">Java常量</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#自动类型转换"><span class="nav-number">5.</span> <span class="nav-text">自动类型转换</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">vlsion_</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Mist</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  










  <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
  <script src="//unpkg.com/valine/dist/Valine.min.js"></script>
  
  <script type="text/javascript">
    var GUEST = ['nick','mail','link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item=>{
      return GUEST.indexOf(item)>-1;
    });
    new Valine({
        el: '#comments' ,
        verify: false,
        notify: false,
        appId: '9mmqXgbwBLayRV0R9zW2iCxe-gzGzoHsz',
        appKey: 'U0JFc0fpsnrOvTdgoBKRSXwz',
        placeholder: 'Just go go',
        avatar:'mm',
        guest_info:guest,
        pageSize:'10' || 10,
    });
  </script>



  





  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
  <script>AV.initialize("", "");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  

  
  

  

  

  

</body>
</html>
